package com.lzk.controller;

import com.lzk.domain.ResponseResult;
import com.lzk.domain.entity.Link;
import com.lzk.domain.vo.PageVo;
import com.lzk.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * author: 刘中魁
 */
@RestController
@RequestMapping("/content/link")
public class LinkController {

    @Autowired
    private LinkService linkService;

    //------------查询所有 友链----------------
    @GetMapping("/list")
    public ResponseResult getAllLink(Link link,Integer pageNum,Integer pageSize){
        PageVo pageVo = linkService.GetAllLink(link,pageNum,pageSize);
        return ResponseResult.okResult(pageVo);
    }

    //---------------------新增友链----------------
    @PostMapping
    public ResponseResult addLink(@RequestBody Link link){
        linkService.save(link);
        return ResponseResult.okResult();
    }

    //----------------更新友链----------------
    //----------------1 回显信息-----------------
    @GetMapping("/{id}")
    public ResponseResult getLinkMesById(@PathVariable Long id){
        Link link = linkService.getById(id);
        return ResponseResult.okResult(link);
    }
    //-----------------2 修改信息--------------
    @PutMapping
    public ResponseResult updateLink(@RequestBody Link link){
        linkService.updateById(link);
        return ResponseResult.okResult();
    }

    //----------------- 删除友链 ----------------
    @DeleteMapping("/{id}")
    public ResponseResult delecteLink(@PathVariable Long id){
        linkService.removeById(id);
        return ResponseResult.okResult();
    }

}
